<template>
    <div class="wrapper">
        <top-header title="我的咨询"></top-header>
        <list class="item-container">
            <refresh @refresh="loadingDown()"></refresh>
            <cell class="border-cell"></cell>
            <cell v-for="(demo,key) in carSearchList">
                <div class="content"  @click="carDetail(demo.pId)">
                    <image class="content_img" v-if="demo.headImg" :src="demo.headImg"></image>
                    <image class="content_img" v-else src="bmlocal://assets/acw/car.jpg"></image>
                    <div>
                        <text class="content_first">{{demo.pAllname}}</text>
                        <div class="content_two">
                            <text class="content_two1">{{demo.pYear}}</text>
                            <text class="content_two2">{{demo.pKilometre}}</text>
                            <text class="content_two1">{{demo.p1}}</text>
                        </div>
                        <div class="content_third">
                            <text class="content_third_price">{{demo.pPrice+"万元"}}</text>
                            <text class="content_third_price">{{"首付："+Math.ceil((demo.pPrice)*0.07)+"万元"}}</text>  <!--首付款7%-->
                        </div>
                        <div class="content_four">
                            <text class="content_four_text" v-if="demo.selltype!= 1 ">3天无理由</text>
                            <text class="content_four_text">{{demo.selltype!= 1 ? '2万公里质保': '可领取2万公里质保'}}</text>
                            <text class="content_four_text" @click="callPhone(demo.pTel)">{{demo.selltype != 1 ? '联系商家': '联系车主'}}</text>
                        </div>
                    </div>
                </div>
            </cell>
            <cell class="cell" v-if="carSearchList.length <= 0">
                <div class="no-order">
                    <!-- <image src="bmlocal://assets/zst/wudingdan.png" class="noOrderImg"></image> -->
                    <text>暂无咨询</text>
                </div>
            </cell>
            <loading class="loading" @loading="onloading()" :display="showLoading">
                <loading-indicator class="comm-indicator" v-if="!lastPage"></loading-indicator>
                <text class="comm-indicator-text" >{{loadingText}}</text>
            </loading>
        </list>
    </div>
</template>
<script>
import header from '../common/header'
export default {
    components: {
        'top-header': header, 
    },
    data () {
        return {
            token: '',
            showLoading: 'hide',
            searchParam: {
                "limit": 10,
                "order": "desc",
                "page": 1,
                "sort": "addtime",
                "uid": ''
            },
            carSearchList:[],
            lastPage:false,//是否是最后一页
            loadingText:'加载中 ...',
        }
    },
    created () {
        let user = this.$storage.getSync('UserInfo')
        this.token = user.token
        this.searchParam.uid = user.id
        this.getCollectList(this.searchParam)
    },
    eros: {
        beforeBackAppear() {
            this.getCollectList(this.searchParam)
        }
    },
    methods: {
        // 返回
        back () {
            this.$router.back();
        },
        callPhone (phone) {
            this.$coms.call(phone)
        },
        loadingDown() {
          this.carSearchList = []
          this.searchParam.page = 1
          this.getCollectList(this.searchParam)
        },
        onloading() {
            this.showLoading = 'show';
            this.$notice.loading.show();
            this.searchParam.page++
            if (!this.lastPage) {
               this.getCollectList(this.searchParam)
            }
            setTimeout(() => {
                this.$notice.loading.hide();
                this.showLoading = 'hide'
            }, 600)
        },
        // 查询商品列表
        getCollectList (param) {
            this.$notice.loading.show();
            this.$fetch({
                method: 'POST',    // 大写
                name: 'advisory.list', //当前是在apis中配置的别名，你也可以直接绝对路径请求 如：url:http://xx.xx.com/xxx/xxx
                data: param
            }).then(resData => {
                // 成功回调
                this.isShowLoad = false;
                console.log(resData)
                if(resData && resData.errno == 0){
                    let list = resData.data.items
                    for (let i = 0, len = list.length; i < len; i++) {
                        list[i].headImg = list[i].pPics.split(';')[1]
                        this.carSearchList.push(list[i])
                    }
                }
                if(resData.data && this.carSearchList.length >= resData.data.total){
                    this.lastPage = true;
                    this.loadingText = '没有更多'
                }
                this.$notice.loading.hide();
            }, error => {
                // 错误回调
                this.isShowLoad = false;
                this.$notice.toast({ message: error})
                console.log(error)
            })
        },
        // 汽车详情
        carDetail (id) {
            this.$router.open({
                name: 'acw.buycar.cardetail',
                type: 'PUSH',
                params: {carId: id}
            });
        },
    }
}
</script>
<style scoped>
@import 'src/js/css/base.scss';
.iconfont {
    font-family: iconfont;
}
.wrapper{
    background-color: #fff;
}
.item-container {
    width: 750px;
    background-color: #f2f3f4;
}
.cell{
    background-color: #f2f3f4;
    width: 710px;
}
.border-cell {
    background-color: #f2f3f4;
    width: 750px;
    height: 24px;
    align-items: center;
    justify-content: center;
    border-bottom-width: 1px;
    border-style: solid;
    border-color: #e0e0e0;
}
.no-order {
    justify-content: center;
    align-items: center;
    height: 1034px;
    width: 750px;
}
.content{
    flex-direction: row;
    height: 300px;
    border-bottom-width:1px;
    border-color: #e0e0e0;
    align-items: center;
    justify-content: center;
}
.content_first{
    width: 500px;
    color: #666;
    font-size: 30px;
    margin-bottom: 10px;
}
.content_img{
    height: 240px;
    width: 200px;
    margin-right: 10px;
}
.content_two{
    flex-direction: row;
    margin-top: 20px;
    margin-bottom: 20px;
}
.content_third{
    flex-direction: row;
}
.content_two1{
    color: #666;
    font-size: 30px;
    padding-left: 20px;
    padding-right: 20px;
}
.content_two2{
    color: #666;
    font-size: 30px;
    padding-left: 20px;
    padding-right: 20px;
    border-left-style: solid;
    border-left-width: 2px;
    border-left-color: #666;
    border-right-style: solid;
    border-right-width: 2px;
    border-right-color: #666;
}
.content_third_price{
    font-size: 30px;
    color: #f2061a;
    margin-left: 20px;
    margin-right: 40px;
}
.content_four{
    width: 520px;
    flex-direction: row;
    justify-content: space-around;
    padding-top: 10px;
}
.content_four_text{
    font-size: 30px;
    color: #009100;
    border-style: solid;
    border-width: 1px;
    border-color: #009100;
    border-radius: 5px;
    height: 40px;
    line-height: 40px;
    padding-left: 10px;
    padding-right: 10px;
}
</style>
